package com.zty.spring.cloud.service.Impl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.xml.bind.JAXBException;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import com.zty.spring.cloud.entity.City;
import com.zty.spring.cloud.entity.CityList;

import util.XmlBuilder;
@Service
public class CityDataService implements com.zty.spring.cloud.service.CityDataService {


	@Override
	public List<City> findByListCity() throws Exception {
		Resource resource = new ClassPathResource("citylist.xml");
		BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream(), "UTF-8"));
		StringBuffer buffer = new StringBuffer();
		String line ="";
		while((line=br.readLine()) !=null) {
			buffer.append(line);
		}

		br.close();
		// XML转为Java对象
		CityList cityList = (CityList)XmlBuilder.xmlStrToObject(CityList.class, buffer.toString());
		return cityList.getCityList();

	}

}
